<?php
class PhoneForm extends BaseForm {

    public function __construct($suffix = null) {
        $this->index = ($suffix) ? $suffix : '';
        parent::__construct();
    }
    public function setup() {

        $this->setWidgets(array(
            'phone'     . $this->index    => new sfWidgetFormInputText(),
        ));

        $this->setValidators(array(
            'phone'       . $this->index   =>  new sfValidatorRegex(
                                          array('pattern' => '/^[a-zA-Z0-9\-\(\)\{\}\[\]\.\+]+$/','max_length'=>15, 'min_length' => 1, 'required'=>false),
                                          array('invalid'  => 'Only letters, numbers, brackets, (+), dash (-) and dot (.) are allowed.',
                                                'min_length' => 'Phone should be at least 1 character.',
                                                'max_length' => 'Phone should not exceed 15 characters.', 'required' => 'Please enter required field.'
                                                )),
        ));

        $this->widgetSchema->setNameFormat('phone[%s]');
    }
}

?>
